/*
 * DeleteSubRouteAction.java
 * 
 * Created by demory on Jun 2, 2008, 11:21:47 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.actions;

import org.fpdev.core.transit.Route;
import org.fpdev.core.transit.SubRoute;
import org.fpdev.apps.rtemaster.RouteMaster;

/**
 *
 * @author demory
 */
public class DeleteSubRouteAction implements ACAction {

  private Route rte_;
  private String subID_;
  private SubRoute subCopy_;

  public DeleteSubRouteAction(Route rte, String subID) {
    rte_ = rte;
    subID_ = subID;
  }

  public boolean doAction(RouteMaster av) {
    subCopy_ = new SubRoute(rte_.getSubRoute(subID_), av.getEngine());
    rte_.deleteSubRoute(subID_, av.getEngine().getRouteNetwork());
    av.getGUI().getRouteSelectionPanel().updateRoutes(true);
    av.getRouteOps().getRoutes().changesMade();
    av.getGUI().getRouteSelectionPanel().selectRouteByID(rte_.getID());
    return true;
  }

  public boolean undoAction(RouteMaster av) {
    System.out.println("restoring sub w/ path len " + subCopy_.getPath().linkCount());
    rte_.addSubRoute(subCopy_);
    av.getGUI().getRouteSelectionPanel().updateRoutes(true);
    av.getGUI().getRouteSelectionPanel().selectRouteByID(rte_.getID());
    return true;
  }

  public String getName() {
    return "Delete Subroute";
  }
}
